<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>账号注册</title>
    <script src="/jquery/jquery-2.1.1.min.js"></script>
</head>
<body>
<h2>账号注册</h2>
<form class="form-signin" role="form" id="regForm" >
请输入姓名：<input type="text" id="name" name="uname"/><br>
请输入密码：<input type="password" id="password" name="upsw" placeholder="仅支持整数" /><br>
请确认密码：<input type="password" id="passwordTwo" placeholder="仅支持整数"/><br>
<button onclick="register()">注册</button>
</form>
</body>
<script>
    function register() {

        $.post("user/regName", {"uname": $("#uname").val()},function (data) {
            if (data.result==true){
                alert("已存在账户名");
                window.location.href ="reg";
            }
        })

        var password1 = $("#password").val();
        var password2 = $("#passwordTwo").val();
        if (Number(password1) == Number(password2)){
            $.post("user/regDo",$("#regForm").serialize(),function (data) {
                if (data.result==true){
                    alert("注册成功");
                    window.location.href ="login";
                } else {
                    alert("注册失败，请检查数据重试");
                }
            })
        }else {
            alert("两次密码不一致！");
        }
    }
</script>
</html>